@extends('admin.layouts.admin')
@section('header')
    <link rel="stylesheet" href="{{ asset('admin/style/admin.css') }}" media="all">
    <style>
        .output-body {
            white-space: pre-wrap;
            background: #000000;
            color: #00fa4a;
            padding: 10px;
            border-radius: 0;
        }
    </style>

@endsection
@section('content')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline lay-search">
                            <input type="text" name="name" placeholder="名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-search" lay-submit lay-filter="LAY-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layuiadmin-btn-search" lay-submit lay-filter="LAY-reset">
                            <i class="layui-icon layuiadmin-button-btn">重置</i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    {{--<button class="layui-btn layuiadmin-btn-search" data-type="batchdel">批量删除</button>--}}
                    <button class="layui-btn layuiadmin-btn-search" data-type="add">添加</button>
                </div>

                <table id="LAY-form" lay-filter="LAY-form"></table>

                <div style="margin-top: 30px">
                    <pre class="output-body" id="run_data" >

                    </pre>

                </div>

                <script type="text/html" id="tpl_task">
                    <span>@{{d.task.name}}</span>
                </script>

                <script type="text/html" id="table-controller">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>运行</a>
                </script>
            </div>
        </div>
    </div>
    <form id="destroy_form" method="post">{{ csrf_field() }} {{ method_field('DELETE') }}</form>
@endsection
@section('scripts')
    <script>
        layui.config({
            base: '../' //静态资源所在路径
        }).use([ 'table', 'form'], function(){
            var $ = layui.$
                ,form = layui.form
                ,table = layui.table
                ,views = layui.view;
            //
            var layArray = new Array($,form,table,views)
            /**
             * 表格列表
             */
            var cols = [[
                {type: "checkbox", fixed: "left"},
                {type:  "numbers", title: "ID"}
                ,{field: "task", title: "Task",  templet:"#tpl_task"}
                ,{field: "expression", title: "Run at"}
                ,{field: "nextRunDate", title: "Next run time"}
                ,{field: "description", title: "Description"}
                ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-controller'}]];
            var initTable = Common.initTable(cols);

            /**
             * 监听搜索
             */
            form.on('submit(LAY-search)', function(data){
                Common.search(data,1);
            });

            /**
             * 监听重置
             */
            form.on('submit(LAY-reset)', function(data){
                $('.lay-search input').val('');
                $(".layui-form select").find("option:first").prop("selected", true);
                form.render();
                Common.search(data,2);
            });

            /**
             * 监听锁定操作
             */
            form.on('checkbox(lockDemo)', function(obj){
                // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
                var url = "{:url('SystemConfigCategory/setStatus')}?id=" + this.value;
                Common.setStatus(url)
            });
            /**
             * 监听排序
             */
            table.on('sort(LAY-form)', function(obj){
                Common.sort(obj);
            });

            /**
             * 监听单元格编辑
             **/
            table.on('edit(LAY-form)', function(obj){
                var postUrl = "/admin/category/update/" + obj.data.id
                Common.editCols(postUrl,obj);
            });

            /**
             * 操作监听 删除和修改
             * @controllers del edit
             */
            table.on("tool(LAY-form)", function(e) {
                if ("del" === e.event) {
                    var postUrl = "/admin/article/destroy/" + e.data.id;
                    Common.deleteTable(postUrl,e);
                }else if ("edit" === e.event) {

                    var id = $(this).parents('tr').data('index');
                    $.ajax({
                        type:"post",
                        url: '{{ route('admin.scheduling.scheduling_run') }}',
                        headers:{
                            'X-CSRF-TOKEN': layui.$('meta[name="csrf-token"]').attr('content')
                        },
                        data: {'id': id},
                        error:function(){
                            Common.systemReturn('系统错误!');
                        },
                        success:function(data){
                            if(data.status == true){
                                $('#run_data').text(data.data)
                                Common.successReturn(data);
                            }else{
                                Common.errorReturn(data)
                            }
                        }



                    });
                }
            });



        });//use

    </script>

@stop
